package fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.gongxiangcheng.R;
import com.recker.flybanner.FlyBanner;
import com.zaaach.citypicker.CityPickerActivity;


import java.util.ArrayList;
import java.util.List;

import activity.mineQbZcActivity;
import activity.mineSsActivity;
import activity.mineZuiXinActivity;
import adapter.RecyAdapter;
import base.BaseFragment;
import progressview.SpringProgressView;

import static android.app.Activity.RESULT_OK;


/**
 * Created by Administrator on 2017/3/27.
 */

public class MineFragment extends BaseFragment {
    private static final int REQUEST_CODE_PICK_CITY = 233;
    private FlyBanner flyBanner;
    private LinearLayout linearLayout,linearLayout2,linearLayout3,linearLayout4;
    private SpringProgressView springProgressView;
    private RecyclerView recyclerView;
    private LinearLayoutManager mLayoutManager;
    private RecyAdapter mAdapter;
    private List<String> mData;
    private ImageView imageView;
    private TextView textView;


    @Override
    protected View initview() {
        return null;
    }
    protected void initData() {
        super.initData();

    }



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_mine, container, false);

          //定位
         textView = (TextView) view.findViewById(R.id.cs_xz_tv);
         textView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 startActivityForResult(new Intent(getActivity(), CityPickerActivity.class),
                         REQUEST_CODE_PICK_CITY);


             }
         });

         //搜索
        imageView = (ImageView) view.findViewById(R.id.mine_ss_iv);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), mineSsActivity.class);
                startActivity(intent);

            }
        });





        linearLayout = (LinearLayout) view.findViewById(R.id.ll_zui_xin);
        linearLayout2 = (LinearLayout) view.findViewById(R.id.ll_j_j_js);
        linearLayout3 = (LinearLayout) view.findViewById(R.id.ll_q_b_zc);
        linearLayout4 = (LinearLayout) view.findViewById(R.id.ll_wd_xm);




        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), mineZuiXinActivity.class);
                startActivity(intent);
            }
        });
        linearLayout2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), mineZuiXinActivity.class);
                startActivity(intent);
            }
        });


        linearLayout3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), mineQbZcActivity.class);
                startActivity(intent);
            }
        });
         linearLayout4.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent = new Intent(getActivity(), mineZuiXinActivity.class);
                 startActivity(intent);
             }
         });







        mData = new ArrayList<>();
        for(int i=0;i<20;i++){
            mData.add("Item "+i);
        }


         recyclerView = (RecyclerView) view.findViewById(R.id.My_recyclerView);
         mLayoutManager = new LinearLayoutManager(getActivity());
         recyclerView.setNestedScrollingEnabled(false);
         //2 为RecyclerView创建布局管理器，这里使用的是LinearLayoutManager，表示里面的Item排列是线性排列
         recyclerView.setLayoutManager(mLayoutManager);
         mAdapter = new RecyAdapter(mData);
         //3 设置数据适配器
         recyclerView.setAdapter(mAdapter);


        /**
         * 进度条
         */




        /**
         * 加载本地图片
         */
         flyBanner = (FlyBanner) view.findViewById(R.id.banner_1);
            List<Integer> images = new ArrayList<>();
            images.add(R.drawable.a);
            images.add(R.drawable.b);
            images.add(R.drawable.c);
            images.add(R.drawable.d);
            images.add(R.drawable.b);
            flyBanner.setImages(images);

            flyBanner.setOnItemClickListener(new FlyBanner.OnItemClickListener() {
                @Override
                public void onItemClick(int position) {
                }
            });
        return view;
    }


    //定位
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQUEST_CODE_PICK_CITY && resultCode == RESULT_OK) {
            if (data != null) {
                String city = data.getStringExtra(CityPickerActivity.KEY_PICKED_CITY);
                textView.setText(city);
            }
        }
    }
}
